from . import view
from . import schema
from fastapi import APIRouter, Security
from package.fastapi import permission

router_plat = APIRouter(prefix='/plat', tags=['平台搜索'])
router_meta = {'module': '数据可视化', 'sub_module': '平台搜索'}

router_proxy = APIRouter(prefix='/proxy', tags=['外部数据集'])
router_proxy_meta = {'module': '数据可视化', 'sub_module': '外部数据集'}


@router_plat.post('/search', openapi_extra=router_meta, name='plat_search', summary='平台日志搜索')
def plat_search(search: schema.PlatQuery,
                page: int = 1,
                page_size: int = 10,
                user=Security(permission.get_user_funcable, scopes=[])):
    return view.plat.plat_search(search.dict(by_alias=True, exclude_unset=True), page=page, page_size=page_size)


@router_proxy.post('/search', openapi_extra=router_meta, name='proxy_search', summary='外部搜索')
def proxy_search(search: schema.ProxyQuery,
                 user=Security(permission.get_user_funcable, scopes=[])):
    return view.proxy.search(search.proxy_configure, search.search_configure)
